import unittest

from parameterized import parameterized
from requests import session

from api.login import Login
from config import local_path
from utils.json_data_utils import JsonDataUtils


class TestLoginPara(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.session = session()
        cls.login = Login()

    @classmethod
    def tearDownClass(cls):
        cls.session.close()

    # 实现登录的参数化
    @parameterized.expand(JsonDataUtils().get_data(f'{local_path}/data/login.json'))
    def test_login(self, keywords, password, code, status, message):
        login_data = {"keywords": keywords, "password": password}
        res = self.login.login(self.session, login_data)
        self.assertEqual(res.status_code, code)
        self.assertEqual(res.json().get("status"), status)
        self.assertIn(message, res.json().get("description"))